package com.yamanyar.weebill.view;

import java.io.Serializable;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;

import com.yamanyar.weebill.domain.Role;
import com.yamanyar.weebill.service.RoleService;

/**
 * Creates a Role. Created in Jun 28, 2008.
 * 
 * @author Kaan Yamanyar
 */
@org.springframework.stereotype.Component("createRole")
@Scope("request")
public class CreateRole implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6785907946599065081L;

	private RoleService roleService;

	private Role role = new Role();

	@Autowired
	public CreateRole(RoleService roleService) {
		this.roleService = roleService;
	}

	public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

	public String save() {
		roleService.createNew(role);
		FacesMessage facesMessage = new FacesMessage(
				FacesMessage.SEVERITY_INFO, "ROLE is saved successfully", "OK");
		FacesContext.getCurrentInstance().addMessage(null, facesMessage);
		role = new Role();
		return null;
	}
}
